import React from 'react';
import {Button} from 'antd';
import {inject, observer} from 'mobx-react';
import {WeaTop, WeaTab, WeaRightMenu, WeaDialog, WeaLocaleProvider} from  'ecCom';
import {WeaTableNew} from 'comsMobx';
import {Condition, getAdButtons} from '../list/ListCondition';

const WeaTable = WeaTableNew.WeaTable;
const getLabel = WeaLocaleProvider.getLabel;

@inject('wfDealRepetitionStore')

@observer


export default class Main extends React.Component {

    constructor(props) {
        super(props);
        const {wfDealRepetitionStore} = this.props;
    }

    doInit() {
        const {wfDealRepetitionStore} = this.props;
        wfDealRepetitionStore.initDatas();
    }

    componentDidMount() {
        this.doInit();
    }


    getSelectedRowKeysTail = () => {
        const {wfDealRepetitionStore} = this.props;
        const {tableStore} = wfDealRepetitionStore;
        const tableNow = tableStore;
        const selectedRowKeys = tableNow.selectedRowKeys;
        const idsJson = JSON.stringify(selectedRowKeys);
        let ids = idsJson.slice(1, idsJson.length - 1).replace(/\"/g, "");
        return ids;
    }

    batchBack = () => {
        const ids = this.getSelectedRowKeysTail();
        window.agentOperate.takeBackBatch(ids, true);
    }

    handleCancel = () => {
        const {wfDealRepetitionStore} = this.props;
        wfDealRepetitionStore.setVisible(false);
    }

    getButtons() {
        let btns;
        const ids = this.getSelectedRowKeysTail();
        btns = [
            (
                <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@loe73d@batchBack`} className='tabDisabledStyle' style={{marginRight: '10px'}} type='primary' disabled={!ids} onClick={this.batchBack}>{getLabel(33243,'批量收回')}</Button>),
        ];
        return btns;
    }

    getFooter() {
        let btns = [];
        btns.push(
            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@yqxcvq@cancel`} type="glost" onClick={this.handleCancel}>{getLabel(31129,'取消')}</Button>
        )
        return btns;
    }

    getMoreBtns() {

        const ids = this.getSelectedRowKeysTail();
        let btns = {
            datas: [],
            collectParams: {
                favname: getLabel(125031,`与当前代理设置存在冲突的代理设置列表`),
                favouritetype: 2,
                objid: 0,
                importantlevel: 1,
            }
        };

        btns.datas.push(
            {
                key: "addAgent",
                icon: <i className="icon-coms-New-Flow"/>,
                content: getLabel(33243,'批量收回'),
                disabled: !ids,
                onClick:this.batchBack
            },
        )


        return btns;
    }
    hideSearchAd = () => this.props.wfDealRepetitionStore.setShowSearchAd(false);
    setShowSearchAd = bool => { this.props.wfDealRepetitionStore.setShowSearchAd(bool)};
    onSearchChange = v => {this.props.wfDealRepetitionStore.setFormFields({requestname: {value: v}})};
    onSearch = v => {this.props.wfDealRepetitionStore.doSearch()};
    render() {
        const {wfDealRepetitionStore} = this.props;
        const {dealRepetiVisible, tableStore, form, showSearchAd} = wfDealRepetitionStore;
        const formParams = form.getFormParams() || {};
        return (
            <div>
                <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@9vsy4h`}
                    className="wf-dealRepetition"
                    visible={dealRepetiVisible}
                    title={getLabel(125031,`与当前代理设置存在冲突的代理设置列表`)}
                    icon="icon-coms-workflow"
                    iconBgcolor='#0079DE'
                    maskClosable={false}
                    // buttons={this.getFooter()}
                    onCancel={this.handleCancel}
                    hasScroll={false}
                    style={{width: '974px', height: '490px'}}
                    moreBtn={this.getMoreBtns()}
                >
                    <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@xm039j`} {...this.getMoreBtns()}>
                        <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@59xmwr`}
                            buttons={this.getButtons()}
                            buttonsAd={getAdButtons(wfDealRepetitionStore)}
                            searchType={['advanced']}
                            searchsBaseValue={formParams.requestname}
                            hideSearchAd={this.hideSearchAd}
                            showSearchAd={showSearchAd}
                            hasMask={false}
                            setShowSearchAd={this.setShowSearchAd}
                            searchsAd={
                                <Condition ecId={`${this && this.props && this.props.ecId || ''}_Condition@rqhkeg`} listStore={wfDealRepetitionStore}/>
                            }
                            onSearchChange={this.onSearchChange}
                            onSearch={this.onSearch}
                        />
                        <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@60hy5i`}
                            comsWeaTableStore={tableStore}
                            hasOrder={true}
                            needScroll={true}
                        />
                    </WeaRightMenu>

                </WeaDialog>
            </div>
        )
    }
}